package nba.com.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import common.event.Behavior;
import common.widget.ListViewAdapter;
import common.widget.ViewTag;
import nba.com.action.Actions;
import nba.com.activity.R;
import nba.com.data.MatchBothData;
import nba.com.data.TeamLogoProvider;

public class ScheduleListAdapter extends ListViewAdapter
{
	public ScheduleListAdapter(Context context)
	{
		super(context);
	}

	public View getView(int position, View convertView, ViewGroup parent)
	{
        if (convertView == null) 
        {
            convertView = mInflater.inflate(R.layout.schedule_list_item, null);
        }
        
        MatchBothData itemData=(MatchBothData)itemDataList.get(position);
        String homeName=itemData.getHomeData().getTeamName();
    	String guestName=itemData.getGuestData().getTeamName();
        Drawable guestDrawable=TeamLogoProvider.getTeamLogoForSchedule(convertView.getContext(),guestName);
    	String guestScore=itemData.getGuestData().getWholeScore();
    	Drawable homeDrawable=TeamLogoProvider.getTeamLogoForSchedule(convertView.getContext(),homeName);
    	String homeScore=itemData.getHomeData().getWholeScore();
    	String beginTime=itemData.getBeginTime();
    	String state=itemData.getState();
    	String id=itemData.getId();

        ImageView guestImageView = (ImageView) convertView.findViewById(R.id.guest_logo);
        guestImageView.setImageDrawable(guestDrawable);
        ImageView homeImageView = (ImageView) convertView.findViewById(R.id.home_logo);
        homeImageView.setImageDrawable(homeDrawable);
        TextView textView = (TextView) convertView.findViewById(R.id.guest_score);
        textView.setText(guestScore);
        textView.setPadding(5, 0, 0, 0);
        textView = (TextView) convertView.findViewById(R.id.home_score);
        textView.setText(homeScore);
        textView.setPadding(5, 0, 0, 0);
        textView = (TextView) convertView.findViewById(R.id.home_name);
        textView.setText(homeName);
        textView.setPadding(5, 0, 0, 0);
        textView = (TextView) convertView.findViewById(R.id.guest_name);
        textView.setText(guestName);
        textView.setPadding(5, 0, 0, 0);
        textView = (TextView) convertView.findViewById(R.id.begin_time);
        textView.setText(beginTime);
        textView.setPadding(5, 0, 0, 0);
        textView = (TextView) convertView.findViewById(R.id.state);
        textView.setText(state);
        textView.setPadding(5, 0, 0, 0);
        
        
        ViewTag tag=new ViewTag(convertView);
        Behavior bv=new Behavior(Actions.ACTION_FORWARD_VIEW);
        bv.addParam(Actions.EXTRA_PAGENAME, "match");
        bv.addParam(Actions.EXTRA_MATCH_ID, id);
        tag.setBv(bv);
   

        return convertView;
	}

}
